/*
 * ------------------------------------------------------------------
 * wechat处理中间件
 * ------------------------------------------------------------------
 * @关于我：
 * QQ:2815473064
 * wechat:13531609457
 * ------------------------------------------------------------------
 */
const { getAccessToken } = require("../../api/wechat");
module.exports = async (req, res, next) => {
  try {
    // 当前时间
    let date_now = req.date_now;
    // 微信appid
    let appid = "wxe4a68dbe11d3bbdf";
    // 微信secret
    let secret = "d1326a040dd5e1b55a8a5d15e70c426d";
    // 将appid 存放至req
    req.wechat_appid = appid;
    // 将secret 存放至req
    req.wechat_secret = secret;
    // 获取access_token记录语句
    let access_token_result = await getAccessToken();
    req.wechat_access_token = access_token_result.access_token;
    next();
  } catch (err) {
    throw { code: 500, statusCode: 500, msg: "wechat 处理中间件出现错误" };
  }
};
